<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/10/28
  Time: 15:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <base href="${pageContext.request.contextPath}/">
    <title>Title</title>
    <script src="jq/jquery.js"></script>
</head>
<body>
    <h1 align="center">修改电池信息页面</h1>
    <form action="PowerBatteryUpdate?id=${sessionScope.id}" method="post">
        <table align="center" border="1px">
            <tr>
                <td>车辆类型：</td>
                <td><input type="text" id="carName" name="carName" value="${sessionScope.powerBattery.carName}"></td>
            </tr>
            <tr>
                <td>所属城市：</td>
                <td><input type="text" id="cityName" name="cityName" value="${sessionScope.powerBattery.cityName}"></td>
            </tr>
            <tr>
                <td>使用单位：</td>
                <td><input type="text" id="userName" name="userName" value="${sessionScope.powerBattery.userName}"></td>
            </tr>
            <tr>
                <td>压差报警值：</td>
                <td><input type="text" id="pressureValue" name="pressureValue" value="${sessionScope.powerBattery.pressureValue}"></td>
            </tr>
            <tr>
                <td>报警时间：</td>
                <td><input type="text" id="time" name="time" value="${sessionScope.powerBattery.time}"></td>
            </tr>
            <tr>
                <td>操作：</td>
                <td><input type="submit" value="修改"></td>
            </tr>
        </table>
    </form>
</body>
    <script>
        //单击“提交”按钮提交表单
        $('form').submit(function(){
            var flag=true;
            if(!CheckCarName()) flag=false;
            else if(!CheckCityName()) flag=false;
            else if(!CheckUserName()) flag=false;
            else if(!CheckPressureValue()) flag=false;
            else if(!CheckTime()) flag=false;
            return flag;
        })

        function CheckCarName(){
            var carName=$('#carName').val();
            if(carName==""){
                alert("请填写完整的信息")
                return false;
            }
            return true;
        }

        function CheckCityName() {
            var cityName = $('#cityName').val();
            if(cityName == ""){
                alert("请填写完整的信息")
                return false;
            }
            return true;
        }

        function CheckUserName() {
            var userName = $('#userName').val();
            if (userName == "") {
                alert("请填写完整的信息")
                return false;
            }
            return true;
        }

        function CheckPressureValue() {
            var pressureValue = $('#pressureValue').val();
            if (pressureValue == "") {
                alert("请填写完整的信息")
                return false;
            }else if(isNaN(parseInt(pressureValue))){
                alert("压差报警值必须是数值类型")
                return false;
            }
            return true;
        }

        function CheckTime() {
            var time = $('#time').val();
            var time_msg = /^(\d{4})-(\d{2})-(\d{2})$/;
            if (time == "") {
                alert("请填写完整的信息")
                return false;
            }else if(time_msg.test(time) == false){
                alert("时间格式不合法，正确格式是yyyy-MM-dd")
                return false;
            }
            return true;
        }
    </script>
</html>
